package com.mojo.jvm.lock;

/**
 * @author <a href="mailto:sjj@jianzhimao.com">mojo</a>
 * copyright (C), 2013-2022, 广州九尾信息科技有限公司
 * @date 2022/10/24 16:57
 */
public class FinalDemo {
    int i;
    final int j;
    static FinalDemo finalDemo;

    public FinalDemo() {
        this.i = 1;
        this.j = 2;
    }

    //线程A先写
    public static void write() {
        finalDemo = new FinalDemo();
    }

    //线程B后读
    public static void read() {
        FinalDemo fd = finalDemo;
        int a = fd.i;
        int b = fd.j;
    }

    public static void main(String[] args) {
        method1();
        method2();
    }

    public static void method1() {
        int i = 3;
        if (i == 3) {

            throw new RuntimeException();
        }
        switch (i) {
            case 1:
                System.out.println(">>>>1");
                break;
            case 2:
                System.out.println(">>>>2");
            default:
                return;
        }
        System.out.println("1>>>>wancheng");
    }
    private static void method2() {
        int i = 1;
        switch (i) {
            case 1:
                System.out.println(">>>>1");
                break;
            case 2:
                System.out.println(">>>>2");
            default:
                return;
        }
        System.out.println("2>>>>wancheng");
    }
}
